<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ngannv
 * Date: 9/28/12
 * Time: 2:18 PM
 * To change this template use File | Settings | File Templates.
 * //Có thể gen file XML(xử lý đầu vào) lúc submit banner thay vì xử lý đầu ra
 */
require_once '../core/Debug.php'; //System Debug...
require_once '../core/config.php';//System Config...
require_once ROOT_PATH.'core/Init.php';  //System Init...
header("Content-Type:text/xml");
$configs = @CGlobal::$configs['home_banner']['conf_val'];
if ($configs) {
    $configs = unserialize(stripslashes($configs));
} else {
    $configs = array();
}
$dir = scandir(ROOT_PATH.DATA_PATH . "home_banner/");
$i    = 1;
$list = '';
foreach ($dir as $fd) {
    if (is_file(ROOT_PATH.DATA_PATH . "home_banner/$fd")) {
        $ext = strtolower(AZLib::getExtension($fd));
        if (in_array($ext, array('.gif', '.jpg', '.jpeg', '.png'))) {
            $arr = array();

            $arr['stt']  = $i++;
            $arr['name'] = (int)basename($fd, $ext);

            $arr['path'] = DATA_PATH . "home_banner/$fd";
            if (isset($configs[$arr['name']])) {
                $h_banner[$arr['name']] = $configs[$arr['name']]['time'] . '000';
                $arr['time']            = $configs[$arr['name']]['time'];

                if ($configs[$arr['name']]['url'] != '') {
                    $arr['url'] = urldecode($configs[$arr['name']]['url']);
                } else {
                    $arr['url'] = '';
                }
            } else {
                $h_banner[$arr['name']] = 15000;
                $arr['time']            = 15;
                $arr['url']             = '';
            }
            $list .= "  <track>
            <title>" . $arr['nme'] . "</title>
            <location>" . $arr['path'] . "</location>
            <info>" . $arr['url'] . "</info>
        </track>";

        }
    }
}

if ($list) {
    echo '<?xml version="1.0" encoding="utf-8"?><playlist version="1" xmlns="http://xspf.org/ns/0/">
    <trackList>';
    echo $list;
    echo '    </trackList>
</playlist>';
}

